//
//  test_Sort.h
//  TestMac
//
//  Created by 小星星吃KFC on 2021/6/4.
//

#import <Foundation/Foundation.h>

//排序
static void test_Sort(void){
    
    
    //降序NO 升序YES
    NSMutableArray<Person *> *array = [NSMutableArray array];
    {
        Person *p = Person.alloc.init;
        p.name = @"jim2";
        p.age = 2;
        
        Dog *dog =  Dog.alloc.init;
        dog.name = @"dogName2";
        p.dog = dog;
        [array addObject:p];
    }
    {
        Person *p = Person.alloc.init;
        p.name = @"jim2";
        p.age = 1;
        
        Dog *dog =  Dog.alloc.init;
        dog.name = @"dogName1";
        p.dog = dog;
        
        [array addObject:p];
    }
    {
        Person *p = Person.alloc.init;
        p.name = @"jim2";
        p.age = 3;
        
        Dog *dog =  Dog.alloc.init;
        dog.name = @"dogName3";
        p.dog = dog;
        
        [array addObject:p];
    }
    {
        Person *p = Person.alloc.init;
        p.name = @"jim1";
        p.age = 3;
        
        Dog *dog =  Dog.alloc.init;
        dog.name = @"dogName2";
        p.dog = dog;
        [array addObject:p];
    }
    
    
    
    NSSortDescriptor *sort_name = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
    NSSortDescriptor *sort_dog_name = [NSSortDescriptor sortDescriptorWithKey:@"dog.name" ascending:YES];
    
    
    [array sortUsingDescriptors:@[sort_name,sort_dog_name]];
    NSLog(@"排序后array = %@", array);
}

